﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace game
{
    public class PostProcessManager
    {
        struct PPEffectSource
        {
            public PPEffectSource(PostProcessEffect effect)
            {
                this.Effect = effect;
                this.ObjectList = new List<GameObject>();
            }
            public PostProcessEffect Effect;
            public List<GameObject> ObjectList;
        }

        private Scene scene;

        Dictionary<PostProcessEffectType, PPEffectSource> effectObjectLists
            = new Dictionary<PostProcessEffectType, PPEffectSource>();

        public PostProcessManager(Scene scene)
        {
            this.scene = scene;
            effectObjectLists[PostProcessEffectType.GLOW] = new PPEffectSource(new Glow(scene));
        }

        public void Update(GameTime gameTime)
        {
            foreach (PPEffectSource effectSrc in effectObjectLists.Values)
            {
                effectSrc.ObjectList.Clear();
            }

            foreach (GameObject obj in scene)
            {
                if (obj.PPEffectTypes == null)
                    continue;
                foreach (PostProcessEffectType effectType in obj.PPEffectTypes)
                {
                    effectObjectLists[effectType].ObjectList.Add(obj);
                }
            }
        }

        public void Draw(GameTime gameTime)
        {
            foreach (KeyValuePair<PostProcessEffectType, PPEffectSource> effectSrc
                in effectObjectLists)
            {
                effectSrc.Value.Effect.Draw(gameTime, effectSrc.Value.ObjectList);
            }
        }
    }
}
